﻿using Architecture.Domain;
using Architecture.Repository;
using Example.Res.Interface;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Example.Res.Impl
{
    public class UserInfoRepository : BaseRepository, IUserInfo
    {
        public UserInfoRepository(DBHelper db) : base(db)
        {

        }
        public async Task<int> AddAsync(UserInfo t)
        {
            string sql = "insert into UserInfo (userName,pwd) values  (@userName,@pwd)";
            SqlParameter[] values = {
                new SqlParameter("@userNae",t.UserName),
                new SqlParameter("@pwd",t.Password)
            };

            int result = await _db.ExecuteNonQueryAsync(sql, values);
            return result;
        }

        public async Task<List<UserInfo>> GetAllAsync()
        {

            List<UserInfo> result = new List<UserInfo>();

            string sql = "select * from userinfo ";

            result = await _db.GetListDataBySqlWhere<UserInfo>(sql);


            //DataTable  行 列表
            //DataSet   table1  table2 table3
            //DataSet set = await _db.Search(sql);

            //DataTable dt = set.Tables.Count > 0 ? set.Tables[0] : new DataTable();

            //if (dt.Rows.Count > 0)
            //{
            //    foreach (DataRow item in dt.Rows)
            //    {
            //        UserInfo userInfo = new UserInfo();
            //        userInfo.ID = Convert.ToInt32(item["id"]);
            //        userInfo.UserName = item["UserName"].ToString();
            //        userInfo.Password = item["Password"].ToString();
            //        result.Add(userInfo);
            //    }
            //}

            return result;
        }

        public Task<List<UserInfo>> GetAsync(Expression<Func<UserInfo, bool>> expre)
        {
            throw new NotImplementedException();
        }

        public Task<UserInfo> GetModelAsync(int id)
        {
            throw new NotImplementedException();
        }

        public Task<int> Update(UserInfo t)
        {
            throw new NotImplementedException();
        }
    }
}
